<?php

namespace frontend\modules\demo\controllers;

use common\models\demo;
use Yii;
use yii\helpers\Json;

/**
* This is the class for controller "DemoController".
*/
class DemoController extends \frontend\modules\demo\controllers\base\DemoController
{



    public  function actionTypehead($attribute, $q)
    {

        $out = [];
        $data = demo::find()
            ->select($attribute)
            ->andWhere(['LIKE', $attribute, $q])
            ->distinct()
            ->orderBy($attribute)
            ->asArray()
            ->all();
        foreach ($data as $d) {
            $out[] = [
                'value' => $d[$attribute],
            ];
        }
        echo Json::encode($out);

    }


}
